﻿using System;
using System.IO.IsolatedStorage;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Coding4Fun.SlideShow
{
    public class SettingsHelper
    {
        private const string SlideDurationKey = "SlideDuration";
        private const string HoldDurationKey = "HoldDuration";

        public static double SlideDuration
        {
            get { return GetValue(SlideDurationKey, 10.0); }
            set 
            { 
                IsolatedStorageSettings.ApplicationSettings[SlideDurationKey] = value;
                IsolatedStorageSettings.ApplicationSettings.Save();
            }
        }

        public static double HoldDuration
        {
            get { return GetValue(HoldDurationKey, 2.0); }
            set
            {
                IsolatedStorageSettings.ApplicationSettings[HoldDurationKey] = value;
                IsolatedStorageSettings.ApplicationSettings.Save();
            }
        }

        private static T GetValue<T>(string key, T defaultValue)
        {
            try
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
                {
                    return (T)IsolatedStorageSettings.ApplicationSettings[key];
                }
            }
            catch (Exception ex0) { }

            return defaultValue;
        }
    }
}
